//
//  SAInventoryCollectionViewCell.m
//  yidiantong
//
//  Created by 黄志刚 on 2020/10/22.
//

#import "SAInventoryCollectionViewCell.h"
#import "SAProductChooseColorModel.h"
#import "SASalesOrderViewListModel.h"

@interface SAInventoryCollectionViewCell ()

@property (nonatomic, strong) UILabel *colourLab;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UIImageView *iconImageView;

@end

@implementation SAInventoryCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setUpsUbViews];
    }
    return self;
}

-(void)setModel:(SAProductChooseColorList *)model {
    _model = model;
    self.colourLab.text = model.attrName;
    if (model.isSelecd == YES) {
        self.iconImageView.hidden = NO;
        self.colourLab.layer.borderWidth = 0;
        self.colourLab.textColor = kPinkColor;
    }else {
        self.iconImageView.hidden = YES;
        self.colourLab.layer.borderWidth = kScaleNum(1);
        self.colourLab.textColor = kBlackColor;
    }
    
    if ([model.num integerValue] == 0) {
        self.numLab.hidden = YES;
    }else {
        self.numLab.hidden = NO;
        self.numLab.text = model.num;
    }
}

-(void)setColoursModel:(SASalesOrderColoursList *)coloursModel {
    _coloursModel = coloursModel;
    self.colourLab.text = coloursModel.attrName;
    if (coloursModel.isSelecd == YES) {
        self.iconImageView.hidden = NO;
        self.colourLab.layer.borderWidth = 0;
        self.colourLab.textColor = kPinkColor;
    }else {
        self.iconImageView.hidden = YES;
        self.colourLab.layer.borderWidth = kScaleNum(1);
        self.colourLab.textColor = kBlackColor;
    }
    
    if ([coloursModel.num integerValue] == 0) {
        self.numLab.hidden = YES;
    }else {
        self.numLab.hidden = NO;
        self.numLab.text = coloursModel.num;
    }
}

-(void)setUpsUbViews {
    UIImageView *iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Shop_cell"]];
    iconImageView.frame = SARectMake(0, 8, 52, 26);
    [self.contentView addSubview:iconImageView];
    self.iconImageView = iconImageView;
    
    [self.contentView addSubview:self.colourLab];
    [self.contentView addSubview:self.numLab];
}

-(UILabel *)colourLab {
    if (!_colourLab) {
        _colourLab = [[UILabel alloc] initWithFrame:SARectMake(0, 8, 52, 26)];
        _colourLab.font = kFont(14);
        _colourLab.textColor = kBlackColor;
        _colourLab.layer.borderColor = kColor(200, 200, 200, 1).CGColor;
        _colourLab.layer.borderWidth = kScaleNum(1);
        _colourLab.textAlignment = NSTextAlignmentCenter;
    }
    return _colourLab;
}

-(UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] initWithFrame:SARectMake(44, 0, 16, 16)];
        _numLab.layer.borderColor = kPinkColor.CGColor;
        _numLab.layer.borderWidth = kScaleNum(1);
        _numLab.layer.cornerRadius = kScaleNum(8);
        _numLab.font = kFont(9);
        _numLab.textColor = kRedColor;
        _numLab.textAlignment = NSTextAlignmentCenter;
        _numLab.layer.masksToBounds = YES;
        _numLab.backgroundColor = [UIColor whiteColor];
    }
    return _numLab;
}

@end
